<template>
  <div class="app-container">
    <el-input
      v-model="filterText"
      placeholder="请输入关键字进行过滤"
    ></el-input>
    <el-tree
      :data="subjectList"
      :props="defaultProps"
      :filter-node-method="filterNode"
      ref="tree"
    />

  </div>
</template>
<script>
import { SubjectApi } from '@/api/subject/url-subject'
import { getAction } from '@/api/manage'
export default {
  data() {
    return {
      //过滤文本
      filterText: '',
      // 数据列表
      subjectList: [],
      defaultProps: {
        children: 'children',
        label: 'title'
      },
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    this.fetchNodeList()
  },
  methods: {
    fetchNodeList() {
      getAction(SubjectApi.list).then((res) => {
        this.subjectList = res.data.items
      }).catch((err) => err);
    },
    // 过滤节点
    filterNode(value, data) {
      if (!value) {
        return true
      }
      return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1
    }
  }
}
</script>
<style scoped>
</style>